home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gwu / 4a.c < prev    next >
C/C++ Source or Header  |  1996-01-30  |  69KB  |  2,332 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9. #include "4.h"
  10. #include "attr.h"
  11. #include "setp.h"
  12. #include "evalp.h"
  13. #include "errmsgp.h"
  14. #include "dclmapp.h"
  15. #include "sspansp.h"
  16. #include "nodesp.h"
  17. #include "miscp.h"
  18. #include "smiscp.h"
  19. #include "utilp.h"
  20. #include "chapp.h"
  21.  
  22. static int constraint_kind(Symbol);
  23. static void make_constrained_node(Node, Symbol, int);
  24. static void dereference_node(Node, Symbol);
  25. static Symbol resolve2_attr(Node, Symbol);
  26. static int in_univ_attributes(int);
  27. static void check_bounds_in_range(Node, Node, Symbol);
  28. static void check_array_conversion(Node, Symbol, Symbol);
  29. static int reads_prefix(int, Symbol);
  30.  
  31. int in_type_classes(Symbol sym)                             /*;in_type_classes*/
  32. {
  33.     /* return true if sym in type_classes, as defined in check_type*/
  34.     /* New procedure aqdded for c version */
  35.     return (
  36.          sym == symbol_boolean_type 
  37.       || sym == symbol_discrete_type   
  38.       || sym == symbol_integer_type
  39.       || sym == symbol_real_type
  40.       || sym == symbol_universal_type);
  41. }
  42.  
  43. void check_type_i(Node expn)                                 /*;check_type_i*/
  44. {
  45.     /* check_type('integer_type', expn) */
  46.     check_type(symbol_integer_type, expn);
  47. }
  48.  
  49. void check_type_r(Node expn)                                 /*;check_type_r*/
  50. {
  51.     /* check_type('real_type', expn) */
  52.     check_type(symbol_real_type, expn);
  53. }
  54.  
  55. void check_type_d(Node expn)                                 /*;check_type_d*/
  56. {
  57.     /* check_type('discrete_type', expn) */
  58.     check_type(symbol_discrete_type, expn);
  59. }
  60.  
  61. void check_type_u(Node expn)                                /*;check_type_u*/
  62. {
  63.     /* check_type('universal_type', expn) */
  64.     check_type(symbol_universal_type, expn);
  65. }
  66.  
  67. void check_type(Symbol context_type, Node expn)                /*;check_type*/
  68. {
  69.     /* This procedure performs type checking and operator disambiguation.
  70.      * -expn- is an expression tree, which must have the type -context_type-.
  71.      * This procedure is called in all contexts where the type of
  72.      * an expression is known a priori : assignments, conditionals, etc.
  73.      * The procedure returns the annotated tree for -expn-, labelling each
  74.      * node with its unique type, and resolving overloaded constructs where
  75.      * needed.
  76.      * Some contexts require that a type belong to a class of types instead
  77.      * of one  specific type. For example, a condition must be of a boolean
  78.      * type, not just BOOLEAN.
  79.      */
  80.  
  81.     Set types, otypes;
  82.     Symbol t, old_context;
  83.     Forset    fs1;
  84.  
  85.     if (cdebug2 > 3) TO_ERRFILE("AT PROC :  check_type");
  86.  
  87.     N_TYPE(expn) = symbol_any;        /*By default.*/
  88.     noop_error = FALSE;
  89.  
  90.     resolve1(expn);        /* Bottom-up pass.*/
  91.  
  92.     if (noop_error) {
  93.         noop_error = FALSE;    /* error emitted already*/
  94.         N_TYPE(expn) = symbol_any;
  95.         return;
  96.     }
  97.  
  98.     types = N_PTYPES(expn);
  99.     old_context = context_type;
  100.     if (in_type_classes(context_type)) {
  101.         /* Keep only those that belong to this class.*/
  102.         otypes = set_copy(types);
  103.         types = set_new(0);
  104.         FORSET(t = (Symbol), otypes, fs1);
  105.             if (compatible_types(t, context_type))
  106.                 types = set_with(types, (char *) t);
  107.         ENDFORSET(fs1);
  108.         set_free(otypes);
  109.  
  110.         if (set_size(types) > 1) {
  111.             /* May be overloaded operator: user_defined one hides predefined.*/
  112.             /* types -:= univ_types */
  113.             otypes = set_copy(types); 
  114.             types = set_new(0);
  115.             FORSET(t = (Symbol), otypes, fs1);
  116.                 if (t != symbol_universal_integer && t!= symbol_universal_real)
  117.                     types = set_with(types, (char *)t);
  118.             ENDFORSET(fs1);
  119.             set_free(otypes);
  120.         }
  121.  
  122.         if (set_size(types) == 1) {
  123.             context_type = (Symbol) set_arb (types);
  124.             set_free(types);
  125.         }
  126.         else {
  127.             type_error(set_new1((char *) symbol_any), context_type, 
  128.               set_size(types), expn);
  129.             N_TYPE(expn) = symbol_any;
  130.             set_free(types);
  131.             return;
  132.         }
  133.     }
  134.  
  135.     resolve2(expn, context_type);
  136.  
  137.     if (noop_error) {
  138.         noop_error = FALSE;    /* error emitted already*/
  139.         return;
  140.     }
  141.  
  142.     /* Now emit a constraint qualification if needed.*/
  143.     if (! in_type_classes(old_context)) apply_constraint(expn, context_type);
  144.     if (! in_univ_types(context_type)) eval_static(expn);
  145. }
  146.  
  147. static int constraint_kind(Symbol typ)                     /*;constraint_kind*/
  148. {
  149.     Symbol    d;
  150.  
  151.     if (cdebug2 > 3) {
  152.         TO_ERRFILE("AT PROC :  constraint_kind");
  153.     }
  154.     /* Note that the use of '' in SETL version is translated to zero in
  155.      * the c version. This use of '' is common only to this routine and
  156.      * the next following one.
  157.      */
  158.     if (is_unconstrained(typ) || in_univ_types(typ))  return as_opt;
  159.     if (is_scalar_type(typ)) {
  160.         if (NATURE(typ) == na_enum) return as_opt;
  161.         else return as_qual_range;
  162.     }
  163.     if (is_array(typ))  {
  164.         if (full_others || NATURE(scope_name) == na_record)
  165.             return as_qual_index;
  166.         else return as_opt;
  167.     }
  168.     if (is_record(typ)) {
  169.         if (has_discriminants(typ)) return  as_qual_discr;
  170.         else return as_opt;
  171.     }
  172.     if (is_access(typ)) {
  173.         d = (Symbol) designated_type(typ);
  174.         if (is_scalar_type(d)) return as_opt;
  175.         else if (is_unconstrained(d)) return as_opt;
  176.         else if (is_array(d)) {
  177.             return as_qual_aindex;
  178.         }
  179.         else if (is_record(d)) {
  180.             if (has_discriminants(d)) return as_qual_adiscr;
  181.             else return as_opt;
  182.         }
  183.     }
  184.     return as_opt;
  185. }
  186.  
  187. void apply_constraint(Node expn, Symbol typ)          /*;apply_constraint*/
  188. {
  189.     int    k, constraint;
  190.  
  191.     if (cdebug2 > 3) {
  192.         TO_ERRFILE("AT PROC :  apply constraint");
  193.     }
  194.  
  195.     constraint = constraint_kind(typ);
  196.     /* test of constraint != 0 corresponds to encoding assigned in previous
  197.      * procedure
  198.      */
  199.     k = N_KIND(expn);
  200.  
  201.     /* If node is insert node, lone descendant is original expression.*/
  202.     if (k == as_insert)  apply_constraint(N_AST1(expn), typ);
  203.  
  204.     if (k == as_subtype || k == as_parenthesis || constraint == as_opt)
  205.         return;
  206.     /* the two cases have to be distinguished : a'first..a'last and a'b 
  207.      * in an aggregate, where a qual_range doesn't make any sens.
  208.      */
  209.     if (k == as_attribute
  210.       && ((int) attribute_kind(expn) == ATTR_T_RANGE
  211.       ||  (int) attribute_kind(expn) == ATTR_O_RANGE)
  212.       && constraint == as_qual_range)
  213.         return;
  214.  
  215.     if (k == as_ivalue || (N_TYPE(expn) != typ)
  216.       || (k == as_array_aggregate)
  217.       || (k == as_new && N_AST2(expn) == OPT_NODE)) {
  218.  
  219.         /* The two following lines were in the Setl version : We don't have
  220.          * to keep them since qual_a* is tranformed in qual_* in the code
  221.          * generator
  222.          * if (is_access (typ)) {type_const = (Symbol) designated_type (typ); }
  223.          *    else { type_const = typ; }
  224.          */
  225.         make_constrained_node(expn, typ, constraint);
  226.     }
  227. }
  228.  
  229. static void make_constrained_node(Node expn, Symbol typ, int constraint)
  230.                                                     /*;make_constrained_node*/
  231. {
  232.     Node e_node;
  233.  
  234.     e_node = copy_node(expn);
  235.     N_KIND(expn) = constraint;
  236.     N_AST1(expn) = e_node;
  237.     if (N_AST2_DEFINED(constraint)) N_AST2(expn) = (Node)0;
  238.     if (N_AST3_DEFINED(constraint)) N_AST3(expn) = (Node)0;
  239.     if (N_AST4_DEFINED(constraint)) N_AST4(expn) = (Node)0;
  240.     N_TYPE(expn) = typ;
  241. }
  242.  
  243. int in_priv_types(Symbol s)                                    /*;in_priv_types*/
  244. {
  245.     return (s == symbol_private || s == symbol_limited_private);
  246. }
  247.  
  248. void resolve1(Node expn)                                        /*;resolve1*/
  249. {
  250.     /* This procedure performs the first, bottom-up pass of the type checking
  251.      * and    overload resolution. It     annotates the    expression tree     with the
  252.      * attribute N_PTYPES(expn),  corresponding to the possible  types of the
  253.      * expression.
  254.      */
  255.  
  256.     Fortup ft1;
  257.     Forset fs1, fs2;
  258.     unsigned int    op_name;
  259.     int        exists, i, j, k, tmp1, nat;
  260.     Symbol name, target_type;
  261.     Set names, op_types, array_types;
  262.     Tuple tmp;
  263.     Set tset;
  264.     Node arg, aggregate_node;
  265.     Tuple arg_list;
  266.     Symbol n_t;
  267.     Node lit_name;
  268.     Symbol n;
  269.     Node op_node, args_node;
  270.     Set possible_types;
  271.     Node arg2;
  272.     Symbol nam;
  273.     Node constraint;
  274.     Set ts;
  275.     Symbol t;
  276.     Node ac_expn, type_id;
  277.     Symbol type_mark;
  278.     Symbol desig_type;
  279.     Node c_expr, arg1;
  280.     Node t_node;
  281.     Node e;
  282.     Symbol to_type;
  283.     Set types;
  284.     Node type_node;
  285.     Node low;
  286.     Node high;
  287.     Set t_low, t_high;
  288.     Symbol t1, t2, it, typ;
  289.     Node call_node, index_node;
  290.     Span save_span;
  291.  
  292.     if (cdebug2 > 3) TO_ERRFILE("AT PROC : resolve1 ");
  293.  
  294.     /*if (noop_error ? false) then return; end if; */
  295.     /* TODO: check why noop_error assumed possible non_boolean in above */
  296.     if (noop_error) {
  297.         N_PTYPES(expn) = set_new1((char *) symbol_any);
  298.         return;
  299.     }
  300.  
  301.     op_name = N_KIND(expn);
  302.  
  303.     if (cdebug2 > 3) {
  304. #ifdef IBM_PC
  305.         printf(" resolve1 %p %s\n", expn, kind_str(op_name));
  306. #else
  307.         printf(" resolve1 %ld %s\n", expn, kind_str(op_name));
  308. #endif
  309.     }
  310.  
  311.     switch (op_name) {
  312.     case as_simple_name:
  313.         name = N_OVERLOADED(expn) ? (Symbol) 0 : N_UNQ(expn);
  314.         if (name != (Symbol)0) {
  315.  
  316.             n_t = TYPE_OF(name);
  317.             nat = NATURE(name);
  318.             if ( nat == na_obj
  319.               || nat == na_constant
  320.               || nat == na_in
  321.               || nat == na_inout
  322.               || nat == na_out
  323.               || nat == na_task_obj
  324.               || nat == na_task_obj_spec
  325.               || nat == na_task_type
  326.               || nat == na_task_type_spec) {
  327.                 N_PTYPES(expn) = set_new1((char *) n_t);
  328.             }
  329.             else if (nat == na_type || nat == na_subtype
  330.               || nat == na_enum || nat == na_record
  331.               || nat == na_array || nat == na_access) {
  332.                 N_PTYPES(expn) = set_new1((char *) symbol_any);
  333.                 pass1_error_id("Invalid use of type %", name, "4.4", expn);
  334.             }
  335.             else if (nat == na_discriminant) {
  336.                 /* A discriminant reference can only appear within a  */
  337.                 /* record definition. The rec.type in noted on the node. */
  338.                 save_span = get_left_span(expn);
  339.                 N_KIND(expn) = as_discr_ref;
  340.                 N_AST1(expn) = new_name_node(SCOPE_OF(name));
  341.                 N_AST2(expn) = N_AST4(expn) = (Node) 0;
  342.                 set_span(N_AST1(expn), save_span);
  343.                 N_PTYPES(expn) = set_new1((char *) n_t);
  344.             }
  345.  
  346.             else if (nat == na_void) {
  347.                 N_PTYPES(expn) = set_new1((char *)symbol_any);
  348.                 pass1_error_id("premature use of %", name, "8.3", expn);
  349.                 return;
  350.             }
  351.             else {
  352.                 N_PTYPES(expn) = set_new1((char *) symbol_any);
  353.                 pass1_error_id("Invalid use of identifier %", name, 
  354.                   "4.4", expn);
  355.             }
  356.         }
  357.         else {
  358.             /* The simple name is overloaded: case of a literal or para-*/
  359.             /* meterless function. Reformat with null param. list.*/
  360.             lit_name = copy_node(expn);
  361.             args_node = node_new(as_list);
  362.             N_LIST(args_node) = tup_new(0);
  363.             N_KIND(expn) = as_call;
  364.             N_AST1(expn) = lit_name;
  365.             N_AST2(expn) = args_node;
  366.             resolve1(expn);
  367.         }
  368.         break;
  369.     case as_character_literal:
  370.         N_PTYPES(expn) = set_new(set_size(N_NAMES(expn)));
  371.         FORSET(n = (Symbol), N_NAMES(expn), fs1);
  372.             N_PTYPES(expn) = set_with(N_PTYPES(expn), (char *) TYPE_OF(n));
  373.         ENDFORSET(fs1);
  374.         break;
  375.     case as_op:
  376.     case as_un_op:
  377.     case as_call:
  378.         /* Overloaded constructs. */
  379.  
  380.         op_node = N_AST1(expn);
  381.         args_node = N_AST2(expn);
  382.  
  383.         FORTUP(arg = (Node), N_LIST(args_node), ft1);
  384.             resolve1(arg);
  385.             check_range_attribute(arg);   /* a no-no */
  386.         ENDFORTUP(ft1);
  387.         names = N_NAMES(op_node);
  388.         result_types(expn);
  389.         if (noop_error);    /* Previous error. */
  390.         else if (set_size(N_PTYPES(expn)) == 0)
  391.             type_error(names, (Symbol) 0, 0, expn);
  392.  
  393.         /* All other cases are basic operations on arrays, record, aggregates */
  394.         /* attributes, subtypes, conversions and qualifications. */
  395.         break;
  396.     case as_name:
  397.         find_old(expn);
  398.         resolve1(expn);
  399.         break;
  400.     case as_int_literal:
  401.         N_PTYPES(expn) = set_new1((char *)symbol_universal_integer);
  402.         break;
  403.     case as_real_literal:
  404.         N_PTYPES(expn) = set_new1((char *) symbol_universal_real);
  405.         break;
  406.     case as_string_literal:
  407.         N_PTYPES(expn) = set_new1((char *) symbol_string_type);
  408.         break;
  409.     case as_null:
  410.         N_PTYPES(expn) = find_access_types();
  411.         break;
  412.     case as_aggregate:
  413.         /* Verify that the list    of choices  is properly formatted, and
  414.          * collect  all possible aggregate  types. The types of the in-
  415.          * dividual choices are not used to resolve the aggregate type.
  416.          */
  417.         arg_list = N_LIST(expn);
  418.         exists = FALSE;
  419.         FORTUPI(arg = (Node), arg_list, i, ft1);
  420.             if (N_KIND(arg) == as_choice_list) {
  421.                 exists = TRUE;
  422.                 break;
  423.             }
  424.         ENDFORTUP(ft1);
  425.         if (exists) {
  426.             exists = FALSE;
  427.             for (j = i + 1; j <= tup_size(arg_list); j++) {
  428.                 arg2 = (Node) arg_list[j];
  429.                 if (N_KIND(arg2) != as_choice_list) {
  430.                     exists = TRUE;
  431.                     break;
  432.                 }
  433.             }
  434.         }
  435.         /*    if (exists arg = arg_list(i) | N_KIND(arg) = as_choice_list)
  436.          *    and(exists arg2 in arg_list(i+1..) |
  437.          *     N_KIND(arg2) /= as_choice_list)
  438.          */
  439.         if (exists) {
  440.             Tuple t, t1;
  441.             pass1_error(
  442.               "positional associations must appear first in aggregate", "4.3",
  443.               arg2);
  444.             t = tup_new(i);
  445.             /* N_LIST(expn) = N_LIST(expn)(1..i); */
  446.             t1 = N_LIST(expn);
  447.             for (j = 1; j <= i; j++)
  448.                 t[i] = t1[i];
  449.             N_LIST(expn) = t;
  450.         }
  451.         /* collect all possible aggregate types. */
  452.         N_PTYPES(expn) = find_agg_types();
  453.         break;
  454.     case as_index:
  455.         possible_types = set_new(0);
  456.         {
  457.             Symbol t;
  458.             FORSET(t = (Symbol), valid_array_expn(expn), fs1);
  459.                 possible_types = set_with(possible_types, 
  460.                   (char *) component_type(t));
  461.             ENDFORSET(fs1);
  462.         }
  463.         if (set_size(possible_types) == 0)
  464.             pass1_error("type mismatch in indexing", "4.1.1", expn);
  465.         N_PTYPES(expn) = possible_types;
  466.         break;
  467.     case as_slice:
  468.         /* Slicing operations are equivalent to indexing operations,
  469.          * for type checking purposes. We simply reformat the result
  470.          * of type checking, so that the result type of the slice is
  471.          * the base type of the array expression. If this type is an
  472.          * access type, we must of course dereference it.
  473.          */
  474.         possible_types = valid_array_expn(expn);
  475.  
  476.         if (set_size(possible_types) == 0)
  477.             pass1_error("type mismatch in slice", "4.1.2", expn);
  478.  
  479.         /* N_PTYPES(expn) := {base_type(t)  : t in possible_types}; */
  480.         tset = set_new(0);
  481.         {
  482.             Symbol t;
  483.             FORSET(t = (Symbol), possible_types, fs1);
  484.                 tset = set_with(tset, (char *) t);
  485.             ENDFORSET(fs1);
  486.         }
  487.         set_free(possible_types);
  488.         N_PTYPES(expn) = tset;
  489.         break;
  490.     case as_selector:
  491.         valid_selected_expn(expn);
  492.         break;
  493.     case as_in:
  494.     case as_notin:
  495.         /* The second argument of membership operators is a type_mark or */
  496.         /* a range. */
  497.         op_node = N_AST1(expn);
  498.         args_node = N_AST2(expn);
  499.         tmp = N_LIST(args_node);
  500.         arg1 = (Node) tmp[1];
  501.         arg2 = (Node) tmp[2];
  502.  
  503.         resolve1(arg1);
  504.         if (N_KIND(arg2) == as_range_expression) {
  505.             find_old(arg2);
  506.             k = N_KIND(arg2);
  507.             if (k != as_simple_name && k != as_attribute) {
  508.                 pass1_error("invalid argument for membership operator",
  509.                   "4.4", arg2);
  510.                 return;
  511.             }
  512.             nam = N_UNQ(arg2);
  513.             t = base_type(nam);
  514.             if (in_priv_types(t)) t = nam;
  515.             N_PTYPES(arg2) = set_new1((char *) t);
  516.             /* Missing: range attribute. */
  517.         }
  518.         else {
  519.             if (N_KIND(arg2) != as_attribute) {
  520.                 /* Argument is a range: reformat as subtype of some type. */
  521.                 constraint = copy_node(arg2);
  522.                 N_KIND(arg2) = as_subtype;
  523.                 N_AST1(arg2) = OPT_NODE;
  524.                 N_AST2(arg2) = constraint;
  525.             }
  526.             resolve1(arg2);
  527.  
  528.             /* ts := {t in N_PTYPES(arg2) | is_scalar_type(t)}; */
  529.             ts = set_new(0);
  530.             {
  531.                 Symbol t;
  532.                 FORSET(t = (Symbol), N_PTYPES(arg2), fs1);
  533.                     if (is_scalar_type(t))
  534.                         ts = set_with(ts, (char *) t);
  535.                 ENDFORSET(fs1);
  536.             }
  537.             if (set_size(ts) == 0) {
  538.                 errmsg("bounds of range for membership op must be scalar",
  539.                   "4.4", arg2);
  540.             }
  541.             else N_PTYPES(arg2) = ts;
  542.         }
  543.         /* Now resolve the expression as for any other operator. */
  544.  
  545.         {
  546.             Set  op_name_set;
  547.             N_KIND(expn) = as_op;
  548.             op_name_set = op_name == as_in ? set_new1((char *)symbol_in)
  549.               : set_new1((char *)symbol_notin);
  550.             N_NAMES(op_node) = op_name_set;
  551.             result_types(expn);
  552.             if (noop_error);
  553.             else if (set_size(N_PTYPES(expn)) == 0)
  554.                 type_error(op_name_set, (Symbol)0, 0, expn);
  555.         }
  556.         break;
  557.     case as_all:
  558.         /* dereference operations must apply  to objects     of access type.
  559.          * The type yielded is obtained by dereferencing the type descrip
  560.          * tor of the access object.
  561.          */
  562.         ac_expn = N_AST1(expn);
  563.  
  564.         resolve1(ac_expn);
  565.         /* ??possible_types := {designated_type(t): t in N_PTYPES(ac_expn)
  566.          *      | is_access(t)};
  567.          */
  568.         possible_types = set_new(0);
  569.         {
  570.             Symbol t;
  571.             FORSET(t = (Symbol), N_PTYPES(ac_expn), fs1);
  572.                 if (is_access(t))
  573.                     possible_types = set_with(possible_types,
  574.                       (char *) designated_type(t));
  575.             ENDFORSET(fs1);
  576.         }
  577.         if (set_size(possible_types) == 0) {
  578.             pass1_error("Expect access type for dereference",
  579.               "3.8", ac_expn);
  580.         }
  581.         N_PTYPES(expn) = possible_types;
  582.         break;
  583.     case as_new:
  584.         /* the elaboration of the subtypes may produce additional
  585.          * anonymous types. These are emitted later on (see resolve2)
  586.          * and here are just collected and discarded.
  587.          */
  588.         newtypes = tup_with(newtypes, (char *)tup_new(0));
  589.         desig_type = make_subtype(expn);
  590.         {
  591.             Tuple junk = (Tuple)tup_frome(newtypes);
  592.             tup_free(junk);
  593.         }
  594.         type_id = N_AST1(expn);
  595.         constraint = N_AST2(expn);
  596.  
  597.         type_mark = N_UNQ(type_id);
  598.         if ((constraint == OPT_NODE) &&(is_unconstrained(type_mark))) {
  599.             pass1_error_l("Constraint required in allocator when",
  600.               "initialization is absent", "4.8", expn);
  601.             return;
  602.         }
  603.         else  /* use name of generated subtype to label allocator */
  604.             N_UNQ(type_id) = desig_type;
  605.  
  606.         check_fully_declared(desig_type);
  607.  
  608.         /* Rebuild node as having a designated type and no aggregate. */
  609.         if (constraint != OPT_NODE) {
  610.             type_node = copy_node(expn);
  611.             N_UNQ(type_node) = desig_type;
  612.             N_KIND(type_node) = as_subtype_decl;
  613.         }
  614.         else type_node = type_id;
  615.         N_AST1(expn) = type_node;
  616.         N_AST2(expn) = OPT_NODE;
  617.  
  618.         /* N_PTYPES(expn) := {a in find_access_types() |
  619.          *    compatible_types(desig_type, designated_type(a))};
  620.          */
  621.         {
  622.             Set s;
  623.             Symbol a;
  624.             s = set_new(0);
  625.             FORSET(a = (Symbol), find_access_types(), fs1);
  626.                 if (compatible_types(desig_type, designated_type(a)))
  627.                     s = set_with(s, (char *) a);
  628.             ENDFORSET(fs1);
  629.             N_PTYPES(expn) = s;
  630.         }
  631.         break;
  632.     case as_new_init:
  633.         /* Allocator given by a type mark and an explicit aggregate. */
  634.  
  635.         type_id = N_AST1(expn);
  636.         aggregate_node = N_AST2(expn);
  637.         find_type(type_id);
  638.         desig_type = N_UNQ(type_id);
  639.         if (!is_type(desig_type)) {
  640.             pass1_error("invalid type mark in allocator", "4.8", type_id);
  641.             return;
  642.         }
  643.         else
  644.             if (is_limited_type(desig_type)) {
  645.                 pass1_error_l("initial value not allowed on an ",
  646.                   "allocator for a limited type", "7.4.4", type_id);
  647.                 return;
  648.             }
  649.         if (N_KIND(aggregate_node) == as_parenthesis) {
  650.             /*Remove parenthesis which is an artifact of parsing.*/
  651.             aggregate_node = N_AST1(aggregate_node);
  652.             N_AST2(expn) = aggregate_node;
  653.         }
  654.         resolve1(aggregate_node);
  655.         /* ??N_PTYPES(expn) = {a in find_access_types() |
  656.          *     compatible_types(desig_type, designated_type(a))}; $$ES151
  657.          */
  658.         {
  659.             Symbol a;
  660.             Set s;
  661.             s = set_new(0);
  662.             FORSET(a = (Symbol), find_access_types(), fs1);
  663.                 if (compatible_types(desig_type, designated_type(a)))
  664.                     s = set_with(s, (char *) a);
  665.             ENDFORSET(fs1);
  666.             N_PTYPES(expn) = s;
  667.         }
  668.         N_KIND(expn) = as_new; /* for common processing. */
  669.         break;
  670.     case as_choice_list:
  671.         /* This is used only for the arguments to calls and not for */
  672.         /* aggregates which are handled in complete_r_aggregate. */
  673.  
  674.         c_expr = N_AST2(expn);
  675.         resolve1(c_expr);
  676. #ifdef TBSL
  677.         -- is copy of N_TYPES needed below    ds 8-jan-85
  678. #endif
  679.         N_PTYPES(expn) = N_PTYPES(c_expr);
  680.         break;
  681.     case as_attribute:
  682.         resolv_attr(expn);
  683.         break;
  684.     case as_qual_range:
  685.         /* When qual_range appears in an expression, the bounds have */
  686.         /* been type-checked. Simple extract the known result type. */
  687.         N_PTYPES(expn) = set_new1((char *) N_TYPE(expn));
  688.         break;
  689.     case as_convert:
  690.         /* The result type is the type mark of the conversion. */
  691.  
  692.         t_node = N_AST1(expn);
  693.         arg = N_AST2(expn);
  694.         tmp1 = N_KIND(arg);
  695.         target_type = N_UNQ(t_node);
  696.         if (tmp1 == as_null || tmp1 == as_new || tmp1 == as_new_init
  697.           || tmp1 == as_aggregate || tmp1 == as_string_literal) {
  698.             pass1_error("invalid expression for conversion", 
  699.               "4.6(3)", arg);
  700.             return;
  701.         }
  702.         else if (is_incomplete_type(target_type)) {
  703.             pass1_error("premature use of private type in expression",
  704.               "7.4.1(4)", t_node);
  705.         }
  706.         else {
  707.             resolve1(arg);
  708.             N_PTYPES(expn) = set_new1((char *)target_type);
  709.         }
  710.         break;
  711.     case as_qualify:
  712.  
  713.         t_node = N_AST1(expn);
  714.         arg = N_AST2(expn);
  715.         to_type = N_UNQ(t_node);
  716.         if (!is_type(to_type)) {
  717.             pass1_error("Expect type mark in qualified expression", 
  718.               "4.7", t_node);
  719.             return;
  720.         }
  721.         else if (in_open_scopes(to_type) && is_task_type(to_type)) {
  722.             pass1_error_id("invalid use of type % within its own body",
  723.               to_type, "9.1", t_node);
  724.             return;
  725.         }
  726.         else if (is_incomplete_type(to_type)) {
  727.             pass1_error("premature use of private type in expression",
  728.               "7.4.1(4)", t_node);
  729.             return;
  730.         }
  731.         else N_PTYPES(expn) = set_new1((char *) to_type);
  732.  
  733.         resolve1(arg);
  734.  
  735.         if (noop_error) return;
  736.         else types = N_PTYPES(arg);
  737.  
  738.         exists = FALSE;
  739.         {
  740.             Symbol t;
  741.             FORSET(t = (Symbol), types, fs1);
  742.                 if (compatible_types(to_type, t)) {
  743.                     exists = TRUE;
  744.                     break;
  745.                 }
  746.             ENDFORSET(fs1);
  747.         }
  748.         if (!exists) {
  749.             pass1_error("Expression has wrong type for qualification",
  750.               "4.7", arg);
  751.         }
  752.         break;
  753.     case as_subtype:
  754.         /* For a subtype expression, the bounds expressions  must  be
  755.          * checked against the specified type, if any, or against the
  756.          * type required by context.
  757.          */
  758.         type_node = N_AST1(expn);
  759.         constraint = N_AST2(expn);
  760.         if (N_KIND(constraint) == as_attribute)
  761.             t_low = t_high = N_PTYPES(constraint);
  762.         else {
  763.             low = N_AST1(constraint);
  764.             high = N_AST2(constraint);
  765.             resolve1(low);
  766.             resolve1(high);
  767.             t_low = N_PTYPES(low);
  768.             t_high = N_PTYPES(high);
  769.         }
  770.         if (type_node == OPT_NODE) {
  771.             /* Case of a range expression with no named type. Validate
  772.              * the bounds against each other, and return the possible types.
  773.              */
  774.             possible_types = set_new(0);
  775.             FORSET(t1 = (Symbol), t_low, fs1);
  776.                 FORSET(t2 = (Symbol), t_high, fs2);
  777.                     it = intersect_types(t1, t2);
  778.                     if (it != (Symbol)0) 
  779.                         possible_types = set_with(possible_types, (char *)it);
  780.                 ENDFORSET(fs2);
  781.             ENDFORSET(fs1);
  782.         }
  783.         else {
  784.             int exists1, exists2;
  785.             /* Subtype of a specified type. Validate the bounds against */
  786.             /* it. */
  787.             typ = N_UNQ(type_node);
  788.             possible_types = set_new1((char *) typ);
  789.             /* if (not exists t1 in t_low |compatible_types(typ, t1))
  790.              *  or (not exists t2 in t_high|compatible_types(typ, t2)) then
  791.              */
  792.             exists1 = exists2 = FALSE;
  793.             FORSET(t1 = (Symbol), t_low, fs1);
  794.                 if (compatible_types(typ, t1)) {
  795.                     exists1 = TRUE;
  796.                     break;
  797.                 }
  798.             ENDFORSET(fs1);
  799.             if (exists1 == TRUE) {
  800.                 FORSET(t2 = (Symbol), t_high, fs1);
  801.                     if (compatible_types(typ, t2)) {
  802.                         exists2 = TRUE;
  803.                         break;
  804.                     }
  805.                 ENDFORSET(fs1);
  806.             }
  807.             if (!exists1 || !exists2) {
  808.                 pass1_error("Invalid types in bounds for range",
  809.                   "3.5, 4.1.2", expn);
  810.             }
  811.         }
  812.         N_PTYPES(expn) = possible_types;
  813.         break;
  814.     case as_parenthesis:
  815.         /* A parenthesised  expression carries  a special operator, in
  816.          * order to distinguish it from a variable.(Thus(X) is not a
  817.          * valid OUT parameter for a procedure, and(D) is not a valid
  818.          * use of a discriminant name).
  819.          */
  820.         e = N_AST1(expn);
  821.         resolve1(e);
  822.         N_PTYPES(expn) = N_PTYPES(e);
  823.         break;
  824.     case as_call_or_index:
  825.         /* A call to a parameterless function that returns an array can
  826.          * overload a call  to a function  call with arguments. Resolve
  827.          * each of the trees independently.
  828.          */
  829.         call_node = N_AST1(expn);
  830.         index_node = N_AST2(expn);
  831.         op_node = N_AST1(call_node);
  832.         args_node = N_AST2(call_node);
  833.         FORTUP(arg = (Node), N_LIST(args_node), ft1);
  834.             resolve1(arg);
  835.         ENDFORTUP(ft1);
  836.         result_types(call_node);
  837.         op_types = N_PTYPES(call_node);
  838. #ifdef TBSN
  839.         if (cdebug2 > 3) TO_ERRFILE('op_types ' + str op_types);
  840. #endif
  841.         array_types = set_new(0);
  842.         FORSET(t = (Symbol), valid_array_expn(index_node), fs1);
  843.             t = (Symbol)component_type(t);
  844.             array_types = set_with(array_types, (char *)t);
  845.         ENDFORSET(fs1);
  846.         N_PTYPES(index_node) = array_types;
  847. #ifdef TBSN
  848.         if (cdebug2 > 3) TO_ERRFILE('array_types ' + str array_types);
  849. #endif
  850.         N_PTYPES(expn) = set_union(op_types, array_types);
  851.         break;
  852.     case as_range:    /* A frequent error. */
  853.         pass1_error("Invalid use of discrete range  in expression",
  854.           "4.4", expn);
  855.         N_PTYPES(expn) = set_new1((char *) symbol_any);
  856.         break;
  857.     default:
  858.         /* TBSL: in SETL have op_name = om: use 0 for now */
  859.         if (op_name == 0) {
  860.             /* usually a previous error; often an invalid selected */
  861.             /*  component name. */
  862.             noop_error = TRUE;
  863.         }
  864.         else 
  865.             pass1_error("Invalid operator in expression: ", "4.4, 4.5", expn);
  866.         break;
  867.     }
  868. }
  869.  
  870. void resolv_attr(Node expn)                                  /*;resolv_attr*/
  871. {
  872.     Fortup ft1;
  873.     int        exists, i, j, notexists, nat, attrkind;
  874.     Symbol s1, s;
  875.     Node entry_node;
  876.     Symbol range_typ;
  877.     Node arg2;
  878.     Node  a_node, arg1;
  879.     Symbol type1;
  880.     Node task_node;
  881.     Symbol task, entry_name;
  882.     Set task_types;
  883.     Node index_node;
  884.     static int is_attribute_prefix = FALSE;
  885.  
  886.     a_node = N_AST1(expn);
  887.     arg1 = N_AST2(expn);
  888.     arg2 = N_AST3(expn);
  889.     if (N_KIND(a_node) == as_simple_name)  /* no attribute if simple name here*/
  890.         attrkind = ATTR_any;
  891.     else
  892.         attrkind = (int) attribute_kind(expn); /* numeric code for attribute */
  893.  
  894.     /* verify that BASE appears only as the prefix of another attribute */
  895.     if (attrkind == ATTR_BASE && !is_attribute_prefix)
  896.         errmsg("Invalid use of attribute BASE", "Annex A", expn);
  897.     is_attribute_prefix = TRUE;
  898.  
  899.     /* First - for attributes applying to objects or types, change
  900.      * attrkind to reflect the type of entity to which the attribute
  901.      * is being applied.
  902.      */
  903.     if ( attrkind == ATTR_FIRST || attrkind == ATTR_LAST
  904.       || attrkind == ATTR_RANGE || attrkind == ATTR_LENGTH
  905.       || attrkind == ATTR_SIZE || attrkind == ATTR_CONSTRAINED) 
  906.             attrkind = (int)(attribute_kind(expn) +=(is_type_node(arg1) ? 2:1)); 
  907.  
  908.     /* We find the type of the left argument of the attribute. */
  909.     /* It may be a type name, in which case there is nothing to be */
  910.     /* done. */
  911.  
  912.     if (is_type_node(arg1)) {
  913.         type1 = N_UNQ(arg1);
  914.         if (is_incomplete_type(type1)) {
  915.             premature_access(type1, arg1);
  916.             N_PTYPES(expn) = set_new1((char *) symbol_any);
  917.             return;
  918.         }
  919.         if (is_task_type(type1)
  920.           &&(attrkind != ATTR_BASE
  921.           && attrkind != ATTR_O_SIZE && attrkind != ATTR_T_SIZE
  922.           && attrkind != ATTR_STORAGE_SIZE)) {
  923.             /* may refer to current task */
  924.             if (in_open_scopes(type1))
  925.                 N_UNQ(arg1) = dcl_get(DECLARED(type1), "current_task");
  926.             else
  927.                 /* use of the task type otherwise is invalid.*/
  928.                 pass1_error("invalid use of task type outside of it own body", 
  929.                   "9.1", arg1);
  930.         }
  931.         N_PTYPES(arg1) = set_new1((char *) type1);
  932.     }
  933.     else if (attrkind == ATTR_COUNT) {
  934.         find_entry_name(arg1);
  935.         task_node = N_AST1(arg1);
  936.         entry_node = N_AST2(arg1);
  937.         task_types = N_PTYPES(task_node);
  938.  
  939.         if (entry_node == OPT_NODE || set_size(task_types) == 0) {
  940.             /* previous error*/
  941.             noop_error = TRUE; 
  942.             return;
  943.         }
  944.  
  945.         if (N_KIND(arg1) == as_entry_family_name) {
  946.             entry_name = N_UNQ(entry_node);
  947.             index_node = N_AST3(arg1);
  948.             range_typ = (Symbol) index_type(TYPE_OF(entry_name));
  949.             check_type(range_typ, index_node);
  950.             N_KIND(arg1) = as_entry_name; /* for common processing */
  951.         }
  952.         else {   /* single entry, possibly overloaded */
  953.             if (set_size(N_NAMES(arg1)) > 1) {
  954.                 errmsg("ambiguous entry name for attribute", "9.9", entry_node);
  955.                 return;
  956.             }
  957.             else {
  958.                 entry_name = (Symbol) set_arb(N_NAMES(arg1));
  959.                 N_UNQ(entry_node) = entry_name;
  960.                 N_AST3(arg1) = OPT_NODE; /* discard N_NAMES */
  961.             }
  962.         }
  963.         complete_task_name(task_node, TYPE_OF(SCOPE_OF(entry_name)));
  964.         task= N_UNQ(task_node);
  965.  
  966.         /* The COUNT attribute can only be used immediately within*/
  967.         /* the object executing the task body. */
  968.         exists = FALSE;
  969.         if (N_KIND(task_node) != as_simple_name) exists = TRUE;
  970.         if (!exists) {
  971.             /* check that the task is one of the open scopes */
  972.             notexists = TRUE;
  973.             FORTUPI(s = (Symbol), open_scopes, i, ft1);
  974.                 s = (Symbol) open_scopes[i];
  975.                 if (task == s 
  976.                   || strcmp(original_name(task), "current_task") == 0
  977.                   && SCOPE_OF(task) == s) {
  978.                     notexists = FALSE;
  979.                     break;
  980.                 }
  981.             ENDFORTUP(ft1);
  982.             if (notexists) exists = TRUE; /* not in open scopes */
  983.         }
  984.         if (!exists) {
  985.             /* intervening scopes cannot be subprograms, etc */
  986.             for (j = 1; j <= i-1; j++) {
  987.                 s1 = (Symbol) open_scopes[j];
  988.                 nat = NATURE(s1);
  989.                 if (nat != na_block && nat != na_entry 
  990.                   && nat != na_entry_family) {
  991.                     exists = TRUE;
  992.                     break;
  993.                 }
  994.             }
  995.         }
  996.         if (exists) {
  997.             pass1_error_l( "E\'COUNT can only be used within the body ",
  998.               "of the task containing E", "9.9", expn);
  999.             return;
  1000.         }
  1001.  
  1002.         type1 = symbol_none;
  1003.         N_PTYPES(arg1) = set_new1((char *) symbol_none);
  1004.     }
  1005.     else {
  1006.         resolve1(arg1);
  1007.         if (set_size(N_PTYPES(arg1)) != 1) {
  1008.             pass1_error_str("Invalid argument for attribute %",
  1009.               attribute_str(attrkind), "Annex A, 4.1.4", expn);
  1010.             return;
  1011.         }
  1012.         else
  1013.             type1 = (Symbol) set_arb(N_PTYPES(arg1));
  1014.     }
  1015.  
  1016.     is_attribute_prefix = FALSE;   /* clear flag */
  1017.  
  1018.     /* Verify that the type has received a full declaration. */
  1019.     if (is_incomplete_type(type1)) {
  1020.         /* 'SIZE and 'ADDRESS can be applied to a deffered constant,
  1021.          * in the default expression for record components and non-
  1022.          * generic formal parameters. The nature of the current scope
  1023.          * is either na_record or na_void(formal part or discr. part).
  1024.          */
  1025.         if (!is_type_node(arg1) &&
  1026.           (attrkind == ATTR_O_SIZE || attrkind == ATTR_T_SIZE
  1027.           || attrkind == ATTR_ADDRESS) &&(NATURE(scope_name) == na_void
  1028.           || NATURE(scope_name) == na_record)) {
  1029.             ;
  1030.         }
  1031.         else {
  1032.             premature_access(type1, arg1);
  1033.             N_PTYPES(expn) = set_new1((char *) symbol_any);
  1034.             return;
  1035.         }
  1036.     }
  1037.     /* Verify that attributes have the proper number of arguments. */
  1038.  
  1039.     if (is_scalar_type(type1) &&
  1040.       (  attrkind == ATTR_O_FIRST || attrkind == ATTR_T_FIRST
  1041.       || attrkind == ATTR_O_LAST || attrkind == ATTR_T_LAST)) {
  1042.         if (arg2 != OPT_NODE) {
  1043.             pass1_error_str("Invalid second argument for attribute %",
  1044.               attribute_str(attrkind), "Annex A, 4.1.4", arg2);
  1045.         }
  1046.         else if ((N_KIND(arg1) == as_simple_name &&(!is_type(N_UNQ(arg1))))
  1047.           || (N_KIND(arg1) == as_attribute
  1048.           && (int) attribute_kind(arg1) != ATTR_BASE)) {
  1049.             pass1_error("attribute cannot be applied to scalar object",
  1050.               "Annex A", a_node);
  1051.         }
  1052.     }
  1053.     else if (attrkind == ATTR_LARGE
  1054.      || attrkind == ATTR_SMALL) {
  1055.         if ((N_KIND(arg1) == as_simple_name &&(!is_type(N_UNQ(arg1)))))
  1056.             pass1_error("attribute must be applied to a type",
  1057.                         "Annex A", a_node);
  1058.     }
  1059.     else if (attrkind == ATTR_POS 
  1060.       || attrkind == ATTR_VAL 
  1061.       || attrkind == ATTR_PRED 
  1062.       || attrkind == ATTR_SUCC 
  1063.       || attrkind == ATTR_VALUE 
  1064.       || attrkind == ATTR_IMAGE) {
  1065.         if (arg2 == OPT_NODE) {
  1066.             pass1_error("Missing second argument for attribute ",
  1067.               "Annex A", a_node);
  1068.             return;
  1069.         }
  1070.         else
  1071.             if (!is_type_node(arg1) || (N_KIND(arg1) == as_attribute
  1072.               && (int) attribute_kind(arg1) == ATTR_BASE)) {
  1073.                 pass1_error_l("First argument of attribute must ",
  1074.                   "be a type mark", "Annex A", a_node);
  1075.                 return;
  1076.             }
  1077.     }
  1078.  
  1079.     /* In the case of array attributes, the argument may be an access */
  1080.     /*    object. Dereference it now. */
  1081.     if ((attrkind == ATTR_O_FIRST || attrkind == ATTR_T_FIRST 
  1082.       || attrkind == ATTR_O_LAST || attrkind == ATTR_T_LAST 
  1083.       || attrkind == ATTR_O_RANGE || attrkind == ATTR_T_RANGE 
  1084.       || attrkind == ATTR_O_LENGTH || attrkind == ATTR_T_LENGTH)
  1085.       && is_access(type1)
  1086.       && is_array((Symbol)(designated_type(type1)))) {
  1087.         if (is_fully_private(type1)) {
  1088.             premature_access(type1, arg1);
  1089.             N_PTYPES(expn) = set_new1((char *)symbol_any);
  1090.             return;
  1091.         }
  1092.         dereference_node(arg1, type1);
  1093.         type1 = (Symbol) designated_type(type1);
  1094.     }
  1095.     else if ((attrkind == ATTR_CALLABLE || attrkind == ATTR_TERMINATED)
  1096.       && is_access(type1)) {
  1097.         dereference_node(arg1, type1);
  1098.         type1 = (Symbol) designated_type(type1);
  1099.     }
  1100.  
  1101.     if (arg2 == OPT_NODE) {
  1102.         /* For array attributes, a missing second argument is */
  1103.         /* equivalent to a reference to the first dimension. */
  1104.         arg2 = node_new(as_int_literal);
  1105.         set_span(arg2, get_right_span(N_AST2(expn)));
  1106.         N_VAL(arg2) = strjoin("1", "");
  1107.         N_AST3(expn) = arg2;
  1108.     }
  1109.  
  1110.     /* The  procedure  attribute-type  will  resolve  fully arg2 */
  1111.     /* in the case of array attributes, to obtain a dimension no. */
  1112.  
  1113.     N_PTYPES(expn) =
  1114.       set_new1((char *)attribute_type(attrkind, type1, arg1, arg2));
  1115. }
  1116.  
  1117. /* Made case as_attribute in resolve2 into separate procedure 
  1118.  * resolve2_attr.  Having resolve2_attr return (Symbol)0 in case of pass1_error.
  1119.  */
  1120.  
  1121. static void dereference_node(Node arg1, Symbol type1)    /*;dereference_node*/
  1122. {
  1123.     /* the prefix of several attributes must be appropriate for the type,
  1124.      * i.e.  it can be an access to an entity  of the proper kind. This
  1125.      * routine is called to emit an explicit dereference (.all) in such cases.
  1126.      */
  1127.  
  1128.     Node acc_arg1;
  1129.  
  1130.     if (is_type_node(arg1)) {
  1131.         ;    /* no op */
  1132.     }
  1133.     else {    /* Dereference object */
  1134.         acc_arg1 = copy_node(arg1);
  1135.         N_AST2(arg1) = (Node)0;
  1136.         N_AST3(arg1) = (Node)0;
  1137.         N_AST4(arg1) = (Node)0;
  1138.         N_PTYPES(acc_arg1) = set_new1((char *)type1);
  1139.         N_KIND(arg1) = as_all;
  1140.         N_AST1(arg1) = acc_arg1;
  1141.     }
  1142.     N_PTYPES(arg1) = set_new1((char *)designated_type(type1));
  1143. }
  1144.  
  1145. void resolve2(Node expn, Symbol context_typ)                  /*;resolve2*/
  1146. {
  1147.     /* This procedure performs the second, top-down pass of the
  1148.      * type validation and overloading resolution.
  1149.      * second argument is the type which the expression must yield.
  1150.      * If the expression is overloaded, only one of its instances must
  1151.      * yield  -context_typ-. Once this is ascertained, the known types of the
  1152.      *formals for the top level operator in expression, are propagated
  1153.      * downwards to the actuals.
  1154.      */
  1155.  
  1156.     Fortup ft1;
  1157.     Forset fs1;
  1158.     int        exists, nat, nk;
  1159.     Set types, a_types, ntypes;
  1160.     Set oa_types = (Set) 0;
  1161.     Symbol name, type2, c, rtype, target_type, ntype_sym;
  1162.     Node op_node, args_node, node;
  1163.     Set valid_ops;
  1164.     Symbol op_name, atysym, t2;
  1165.     Set op_names;
  1166.     Tuple tup, indices;
  1167.     Symbol target_typ;
  1168.     Node array1;
  1169.     Symbol array_type;
  1170.     int        out_c;
  1171.     Tuple    index_list;
  1172.     Node index;
  1173.     int        i, may_others;
  1174.     Node discr1, e, ac_expn;
  1175.     Symbol access_type;
  1176.     Node type_node, expn1, entry_node;
  1177.     Symbol alloc_type;
  1178.     Symbol accessed_type;
  1179.     /*char   *chk;*/
  1180.     char    *strvstr;
  1181.     Tuple    strvtup;
  1182.     int        strvlen, strvi;
  1183.     Symbol t;
  1184.     Symbol c1, c2;
  1185.     Set tu;
  1186.     Node t_node, constraint, low, high;
  1187.     Symbol b_type;
  1188.     int        kind;
  1189.     Node call_node, index_node;
  1190.     Const    lv; /*TBSL: check type of lv */
  1191.     char    *orignam;
  1192.     Tuple    litmaptup;
  1193.     int        litmapi;
  1194.     Span    save_span;
  1195.  
  1196.     if (cdebug2 > 0) {
  1197.         TO_ERRFILE("resolve2 ");
  1198. #ifdef IBM_PC
  1199.         printf(" %p %s context %p %s\n"
  1200.           , expn, kind_str(N_KIND(expn)), context_typ,
  1201.           ((context_typ != (Symbol)0)? ORIG_NAME(context_typ):""));
  1202. #else
  1203.         printf(" %ld %s context %ld %s\n"
  1204.           , expn, kind_str(N_KIND(expn)), context_typ,
  1205.           ((context_typ != (Symbol)0)? ORIG_NAME(context_typ):""));
  1206. #endif
  1207.     }
  1208.     if (context_typ == (Symbol)0)
  1209.         printf("??:resolve2 context_typ null\n");
  1210.     if (noop_error) return;
  1211.  
  1212.     types = N_PTYPES(expn);
  1213.  
  1214.     if (expn == OPT_NODE) return;
  1215.  
  1216.     switch (nk = N_KIND(expn)) {
  1217.     case as_simple_name:
  1218.         name = N_UNQ(expn);
  1219.         /* If constant, get its value, and if universal constant,
  1220.          * convert when necessary.
  1221.          */
  1222.         type2 = TYPE_OF(name);
  1223.         if (!compatible_types(context_typ, type2)) {
  1224.             errmsg_id_type("% has incorrect type. Expect %", name, context_typ,
  1225.               "none", expn);
  1226.             noop_error = TRUE;
  1227.             return;
  1228.         }
  1229.         else
  1230.             if ((NATURE(name) == na_out) &&(!out_context)) {
  1231.                 errmsg_id("invalid reading of out parameter %", name, "6.2",
  1232.                   expn);
  1233.             }
  1234.         if (NATURE(name) == na_constant) {
  1235.             if (in_univ_types(type2)) {
  1236.                 copy_attributes((Node) SIGNATURE(name), expn);
  1237.                 specialize(expn, context_typ);
  1238.                 type2 = base_type(context_typ);
  1239.             }
  1240.             else if ((Node) SIGNATURE(name) == OPT_NODE
  1241.               && (NATURE(scope_name) != na_void 
  1242.               && NATURE(scope_name) != na_record)) {
  1243.                 /* Only permissible contexts for a defered constant are
  1244.                  * formal parts and component declarations.
  1245.                  */
  1246.                 errmsg_l("premature use of deferred constant before its",
  1247.                   "full declaration", "7.4.3", expn);
  1248.             }
  1249.         }
  1250.         else eval_static(expn);
  1251.         break;
  1252.     case as_character_literal:
  1253.         exists = FALSE;
  1254.         FORSET(c = (Symbol), N_NAMES(expn), fs1);
  1255.             if (compatible_types(context_typ, TYPE_OF(c))) {
  1256.                 exists = TRUE;
  1257.                 break;
  1258.             }
  1259.         ENDFORSET(fs1);
  1260.         if (exists) {
  1261.             type2 = TYPE_OF(c);
  1262.             /*N_VAL(expn) = literal_map(type2)(original_name(c));*/
  1263.             /* In the C version, create a Const with this value */
  1264.             orignam = ORIG_NAME(c);
  1265.             if (orignam == (char *)0) chaos("resolve2 null literal");
  1266.             litmaptup = (Tuple) literal_map(type2);
  1267.             for (litmapi = 1; litmapi <= tup_size(litmaptup); litmapi += 2) {
  1268.                 if (streq(orignam, litmaptup[litmapi])) {
  1269.                     N_VAL(expn) = (char *) int_const((int)litmaptup[litmapi+1]);
  1270.                     break;
  1271.                 }
  1272.             }
  1273.         }
  1274.         else {
  1275.             char *tmp_msg;
  1276.  
  1277.             tmp_msg = strjoin(N_VAL(expn), " has incorrect type. Expect %");
  1278.             errmsg_type(tmp_msg, context_typ, "none", expn);
  1279.             type2 = symbol_any;
  1280.             N_VAL(expn) = (char *) int_const(0);
  1281.         }
  1282.         N_KIND(expn) = as_ivalue;
  1283.         N_OVERLOADED(expn) = FALSE;
  1284.         N_PTYPES(expn) = (Set) 0;
  1285.         N_NAMES(expn) = (Set) 0;
  1286.         break;
  1287.     case as_op:
  1288.     case as_un_op:
  1289.     case as_call:
  1290.         op_node = N_AST1(expn);
  1291.         args_node = N_AST2(expn);
  1292.         op_names = N_NAMES(op_node);
  1293.  
  1294.         /* Find instance of operator that yields type imposed by context. */
  1295.         valid_ops = set_new(0);
  1296.         FORSET(name = (Symbol), op_names, fs1);
  1297.             if (compatible_types(context_typ, TYPE_OF(name)))
  1298.                 valid_ops = set_with(valid_ops, (char *) name);
  1299.         ENDFORSET(fs1);
  1300.  
  1301.         N_NAMES(op_node) = valid_ops;
  1302.  
  1303.         if (set_size(valid_ops) > 1)
  1304.             disambiguate(expn, context_typ);
  1305.  
  1306.         if (set_size(N_NAMES(op_node)) > 1)
  1307.             /* try removing implicit conversions of universal quantities. */
  1308.             remove_conversions(expn);
  1309.  
  1310.         /* Now there should be only one possiblity left. */
  1311.         valid_ops = N_NAMES(op_node);
  1312.         if (set_size(valid_ops) != 1) {
  1313.             if (cdebug2 > 2) {
  1314. #ifdef TBSN
  1315.                 ??(for nam in valid_ops)
  1316.                     TO_ERRFILE('OVERLOADS ', nam, SYMBTAB(nam));
  1317.                 end for;
  1318. #endif
  1319.             }
  1320.             type_error(op_names, context_typ, set_size(valid_ops), op_node);
  1321.             return;
  1322.         }
  1323.         else {
  1324.             op_name = (Symbol) set_arb(valid_ops);
  1325.             type2   = TYPE_OF(op_name);
  1326.         }
  1327.  
  1328.         N_OVERLOADED(expn) = FALSE; /* DS -check this */
  1329.         N_NAMES(expn) = N_PTYPES(expn) = (Set)0;
  1330.         /* For a predefined operator, the type imposed by context fixes
  1331.          * the types of the arguments. The signature of a predefined op.
  1332.          * contains only classes of types, and it ignored in this pass.
  1333.          * The resulting type must be that of the context.
  1334.          */
  1335.         switch (nat = NATURE(op_name)) {
  1336.         case na_op:
  1337.             type2 = base_type(context_typ);
  1338.             N_UNQ(op_node) = op_name;
  1339.             complete_op_expr(expn, type2);
  1340.             /* The expression "+"(1, 2) is syntactically a function call. At
  1341.              * this point it recognized as an operator node.
  1342.              */
  1343.             if (N_KIND(expn) == as_call)
  1344.                 N_KIND(expn) = (tup_size(N_LIST(args_node)) == 1) ? as_un_op
  1345.                   : as_op;
  1346.  
  1347.             /* For a procedure or function, the signature imposes a type on
  1348.              * each actual parameter present, and specifies a default value
  1349.              * for the ones that are absent. If the function is aliased(ie
  1350.              * a renaming or derivation) the parent subprogram is called.
  1351.              */
  1352.             break;
  1353.         case na_procedure:
  1354.         case na_procedure_spec:
  1355.         case na_function:
  1356.         case na_function_spec:
  1357.             complete_arg_list(SIGNATURE(op_name), args_node);
  1358.             N_KIND(expn) = as_call;
  1359.             N_UNQ(op_node) = op_name;
  1360.             TO_XREF(op_name);
  1361.             break;
  1362.         case na_entry:
  1363.         case na_entry_family:
  1364.             complete_arg_list(SIGNATURE(op_name), args_node);
  1365.             N_KIND(expn) = as_ecall;
  1366.             if (N_KIND(op_node) == as_entry_name
  1367.               || N_KIND(op_node) == as_entry_family_name) {
  1368.                 entry_node = N_AST2(op_node);
  1369.                 /* Note  the unique name on the entry name node. */
  1370.                 N_UNQ(entry_node) = op_name;
  1371.             }
  1372.             else {   /* called from proc_or_entry, no entry name yet */
  1373.                 N_UNQ(op_node) = op_name;
  1374.             }
  1375.             TO_XREF(op_name);
  1376.  
  1377.             /* Resolved enumeration literals are returned as themselves. */
  1378.             break;
  1379.         case na_literal:
  1380.             save_span = get_left_span(expn);
  1381.             N_KIND(expn) = as_simple_name;
  1382.             N_UNQ(expn)  = op_name;
  1383.             set_span(expn, save_span);
  1384.             N_AST2(expn) = (Node)0; /* clear ast */
  1385.             N_VAL(expn)  = ORIG_NAME(op_name);
  1386.             TO_XREF(op_name);
  1387.             break;
  1388.         }
  1389.         /* Remaining cases are basic operations. */
  1390.         break;
  1391.     case as_int_literal:
  1392.         /* If the context  type is not universal, the literal must be trans-
  1393.          * formed to its short SETL form.
  1394.          */
  1395.         target_typ = ((context_typ == symbol_universal_integer)
  1396.           ? symbol_universal_integer : symbol_integer);
  1397.  
  1398.         lv = adaval(target_typ, N_VAL(expn));
  1399.         if (adaval_overflow)
  1400.             create_raise(expn, symbol_numeric_error);
  1401.         else {
  1402.             ast_clear(expn);
  1403.             N_KIND(expn) = as_ivalue;
  1404.             N_VAL(expn) = (char *) lv;
  1405.         }
  1406.         type2 = base_type(context_typ); /* inherited from context */
  1407.         if (root_type(type2) != symbol_integer
  1408.           && root_type(type2) != symbol_universal_integer) {
  1409.             errmsg("invalid context for integer literal", "4.6(15)", expn);
  1410.         }
  1411.         break;
  1412.     case as_real_literal:
  1413.         /* If the context is not universal, or is not a fixed type, then
  1414.          * convert the literal to a floating number.
  1415.          */
  1416.         target_typ = (context_typ == symbol_universal_real
  1417.           || is_fixed_type(root_type(context_typ)))
  1418.           ? symbol_universal_real: symbol_float;
  1419.         lv = adaval(target_typ, N_VAL(expn));
  1420.         if (adaval_overflow)
  1421.             create_raise(expn, symbol_constraint_error);
  1422.         else {
  1423.             ast_clear(expn);
  1424.             N_KIND(expn) = as_ivalue;
  1425.             N_VAL(expn) = (char *) lv;
  1426.         }
  1427.         type2 = base_type(context_typ); /* inherited from context */
  1428.         if (root_type(type2) != symbol_float 
  1429.           && !is_fixed_type(root_type(type2))
  1430.           && root_type(type2) != symbol_universal_real) {
  1431.             errmsg("invalid context for real literal", "4.6(15)", expn);
  1432.         }
  1433.         break;
  1434.     case as_string_literal:
  1435.         if (is_array(context_typ)) {
  1436.             if (context_typ == symbol_string_type) {
  1437.                 /* verify that only one string type is visible. */
  1438.                 context_typ = symbol_string;
  1439.             }
  1440.             else if (is_fully_private(context_typ))
  1441.                 premature_access(context_typ, expn);
  1442.  
  1443.             if (root_type(context_typ) == symbol_string) {
  1444.                 /*N_VAL(expn) := [abs c: c in N_VAL(expn)];*/
  1445.                 strvstr = N_VAL(expn);
  1446.                 strvlen = strlen(strvstr);
  1447.                 strvtup = tup_new(strvlen);
  1448.                 for (strvi = 1; strvi <= strvlen; strvi++)
  1449.                     strvtup[strvi] = (char *) strvstr[strvi-1];
  1450.                 ast_clear(expn);
  1451.                 N_VAL(expn) = (char *) strvtup;
  1452.                 N_KIND(expn) = as_string_ivalue;
  1453.                 N_NAMES(expn) = (Set) 0;
  1454.             }
  1455.             else {
  1456.                 /* Context is user-defined array of a character type. */
  1457.                 complete_string_literal(expn, component_type(context_typ));
  1458.             }
  1459.         }
  1460.         else {
  1461.             errmsg_type("Incorrect type for string literal. Expect %",
  1462.               context_typ, "none", expn);
  1463.         }
  1464.         type2 = context_typ;
  1465.         break;
  1466.     case as_null:
  1467.         if (is_access(context_typ)) type2 = context_typ;
  1468.         else {
  1469.             errmsg("Invalid context for NULL", "3.8.2", expn);
  1470.             return;
  1471.         }
  1472.         break;
  1473.     case as_aggregate:
  1474.         /* Resolve it using the  context type, and apply constraint if any.
  1475.          * The possible types include all visible composite types, and there
  1476.          * should be one of them compatible with the context.
  1477.          */
  1478.         exists = FALSE;
  1479.         FORSET(t = (Symbol), types, fs1);
  1480.             if (compatible_types(t, context_typ)) {
  1481.                 exists = TRUE;
  1482.                 break;
  1483.             }
  1484.         ENDFORSET(fs1);
  1485.         if (!exists) {
  1486.             errmsg_id("No aggregate available for type %", context_typ, "4.2",
  1487.               expn);
  1488.             return;
  1489.         }
  1490.         else complete_aggregate(context_typ, expn);
  1491.  
  1492.         type2 = context_typ;
  1493.  
  1494.         /* in the absence of more precise checks, the type of the
  1495.          * aggregate can only be set to the base type (see end of resolve2
  1496.          */
  1497.         context_typ = base_type (context_typ);
  1498.  
  1499.         /* For arrays, obtain required index type from type of array
  1500.          * expression, and complete the determination of both.
  1501.          */
  1502.         break;
  1503.     case as_index:
  1504.         array1 = N_AST1(expn);
  1505.         index_node = N_AST2(expn);
  1506.  
  1507.         array_type = complete_array_expn(expn, context_typ);
  1508.  
  1509.         /* Previous error*/
  1510.         if (array_type == symbol_any) return;
  1511.         /* Complete resolution of each index.
  1512.          * The  index expression is    a context  in which  out parameters
  1513.          * cannot  be  read. This  has to  be  special-cased     because an
  1514.            * indexed  expression on  the lhs  of an assignment is a  valid
  1515.          * context for an out parameter, and the global flag out_context
  1516.          * is set accordingly in  processing assignments.
  1517.          */
  1518.         out_c = out_context;
  1519.         out_context = FALSE;
  1520.         index_list = N_LIST(index_node);
  1521.  
  1522.         FORTUPI(index = (Node), index_list, i, ft1);
  1523.             resolve2(index, (Symbol) (index_types(array_type))[i]);
  1524.         ENDFORTUP(ft1);
  1525.         out_context = out_c;
  1526.  
  1527.         type2 = (Symbol) component_type(array_type);
  1528.         break;
  1529.     /* For slices, obtain array type, and apply its index type to the
  1530.      * subtype expression for the discrete range.
  1531.      */
  1532.     case as_slice:
  1533.         array1 = N_AST1(expn);
  1534.         index_node = N_AST2(expn);
  1535.         array_type = complete_array_expn(expn, context_typ);
  1536.         /* Previous error*/
  1537.         if (array_type == symbol_any)
  1538.             return;
  1539.         tup = N_LIST(index_node);
  1540.         discr1 = (Node) (tup[1]);
  1541.         resolve2(discr1, (Symbol) index_type(array_type));
  1542.         /*    Replace index list with its sole element. */
  1543.         N_AST2(expn) = discr1;
  1544.         N_AST3(expn) = N_AST4(expn) = (Node) 0;
  1545.         type2 = base_type(array_type);
  1546.         break;
  1547.     case as_selector:
  1548.         type2 = complete_selected_expn(expn, context_typ);
  1549.  
  1550.         /* For a parenthesised expression, resolve the expression, and keep
  1551.          * the parenthesis, to distinguish them from variables. The possible
  1552.          * constraint of the context is not propagated to the expression.
  1553.          * If the context is universal, discard the parenthesis, to enable
  1554.          * full evaluation of universal expressions.
  1555.          */
  1556.         break;
  1557.     case as_parenthesis:
  1558.         e = N_AST1(expn);
  1559.         resolve2(e, base_type(context_typ));
  1560.         if (in_univ_types(context_typ))
  1561.             copy_attributes(e, expn);
  1562.         apply_constraint(e, context_typ);
  1563.         type2 = context_typ;
  1564.         break;
  1565.     /* For a dereference operation, we must verify that the access
  1566.      * object points to the right type.
  1567.      */
  1568.     case as_all:
  1569.         ac_expn = N_AST1(expn);
  1570.         {
  1571.             Symbol t;
  1572.  
  1573.             a_types = set_new(0);
  1574.             FORSET(t = (Symbol), N_PTYPES(ac_expn), fs1);
  1575.                 if (is_access(t)
  1576.                   && compatible_types(context_typ, designated_type(t)))
  1577.                     a_types = set_with(a_types, (char *) t);
  1578.             ENDFORSET(fs1);
  1579.         }
  1580.         /* TBSL: check that t is defined in type_error call dsd 18 aug */
  1581.         if (set_size(a_types) != 1) {
  1582.             remove_conversions(ac_expn);    /* last chance */
  1583.             oa_types = a_types;
  1584.             a_types = set_new(0);
  1585.             FORSET(atysym = (Symbol), N_PTYPES(ac_expn), fs1);
  1586.                 if (set_mem((char *)atysym, oa_types))
  1587.                     a_types = set_with(a_types, (char *) atysym);
  1588.             ENDFORSET(fs1);
  1589.             if (set_size(a_types) != 1) {
  1590. #ifdef TBSL
  1591.                 ]        type_error(set_new1('@'), t, set_size(a_types), expn);
  1592. #endif
  1593.                 set_free(oa_types); 
  1594.                 set_free(a_types);
  1595.                 return;
  1596.             }
  1597.         }
  1598.         access_type = (Symbol) set_arb(a_types);    /* Only one type left. */
  1599.         set_free(a_types);
  1600.         if (oa_types != (Set)0)
  1601.             set_free(oa_types);
  1602.  
  1603.         /* We know already that the nature of access type is na_access. */
  1604.         type2 = (Symbol) designated_type(access_type);
  1605.         /* It is always illegal to dereference an out parameter.*/
  1606.         out_c = out_context;
  1607.         out_context = FALSE;
  1608.         resolve2(ac_expn, access_type);
  1609.         out_context = out_c;
  1610.         break;
  1611.     /* For an allocator, we obtain the type of the access object
  1612.      * by dereferencing the access type. The final expression however
  1613.      * gives the access type, together with the validated access object.
  1614.      */
  1615.     case as_new:
  1616.         type_node = N_AST1(expn);
  1617.         expn1 = N_AST2(expn);
  1618.         alloc_type = N_UNQ(type_node);
  1619.  
  1620.         if (!is_access(context_typ)) {
  1621.             errmsg("Context of allocator must be an access type", "4.8, 3.8",
  1622.               expn);
  1623.             return;
  1624.         }
  1625.  
  1626.         accessed_type = (Symbol) designated_type(context_typ);
  1627.         /* Verify that the allocator matches the context.
  1628.          * The(possibly unconstrained)    access type is    the one given by the
  1629.          * context(eg.    declaration). If the allocator provides a constraint
  1630.          * rather than an aggregate, then a subtype has been created, and the
  1631.          * access type is an access to this constrained type. The  constraint
  1632.          * must     then be  emitted so that it is evaluated at the proper time.
  1633.          *(The subtype is  not an anonymous type, and is introduced  only to
  1634.          * simplify type checking).
  1635.          * The converse may also occur: the  context is     constrained, but the
  1636.          * allocator  type is  unconstrained. In that  case, use  the context
  1637.          * context type as the type of the expression.
  1638.          * Finally,  the context  may be  an unconstrained  array type, whose
  1639.          * index  type    is   nevertheless   bounded.  When   the allocator is
  1640.          * initialized with an aggregate, the bounds of the aggregate must be
  1641.          * compatible with that index type.
  1642.          */
  1643.         if (!compatible_types(accessed_type, alloc_type)) {
  1644.             errmsg_type("Invalid type for allocator. Expect %", accessed_type,
  1645.               "3.8, 4.8", type_node);
  1646.             return;
  1647.         }
  1648.  
  1649.         if (expn1 != OPT_NODE) {
  1650.             res2_check(expn1, alloc_type);
  1651.             if (is_array(accessed_type) && can_constrain(accessed_type)) {
  1652.                 /* bounds of the aggregate will have to be shown to be 
  1653.                  * compatible with the (unconstrained) designated type.
  1654.                  */
  1655.                 make_constrained_node(expn1, accessed_type, as_qual_sub);
  1656.             }
  1657.             else if (!can_constrain(accessed_type)
  1658.               && accessed_type != alloc_type) {
  1659.                 /*A further qualification is necessary.*/
  1660.                 may_others = full_others;
  1661.                 full_others = TRUE;
  1662.                 apply_constraint(expn1, accessed_type);
  1663.                 full_others = may_others;
  1664.             }
  1665.         }
  1666.         else if (is_array(alloc_type) && N_KIND(type_node) == as_subtype_decl) {
  1667.             /* the index subtypes of the type will have to be elaborated. */
  1668.             indices = tup_new(0);
  1669.             { 
  1670.                 Symbol i;
  1671.                 FORTUP(i = (Symbol), index_types(alloc_type), ft1);
  1672.                     indices =
  1673.                       tup_with(indices, (char *) new_subtype_decl_node(i));
  1674.                 ENDFORTUP(ft1);
  1675.             }
  1676.             N_TYPE(expn) = context_typ;
  1677.             make_insert_node(expn, indices, copy_node(expn));
  1678.         }
  1679.  
  1680.         else if (is_access(alloc_type) && N_KIND(type_node) == as_subtype_decl){
  1681.             /* the designated type is anonymous, and will also be elaborated. */
  1682.             indices = tup_new(0);
  1683.             { 
  1684.                 Symbol i, d;
  1685.                 d = (Symbol) designated_type(alloc_type);
  1686.                 if is_array(d) {       /* elaborate indices as well */
  1687.                     FORTUP(i = (Symbol), index_types(d), ft1);
  1688.                         indices =
  1689.                           tup_with(indices, (char *) new_subtype_decl_node(i));
  1690.                     ENDFORTUP(ft1);
  1691.                 }
  1692.                 indices = tup_with(indices, (char *) new_subtype_decl_node(d));
  1693.             }
  1694.             N_TYPE(expn) = context_typ;
  1695.             make_insert_node(expn, indices, copy_node(expn));
  1696.         }
  1697.         type2 = context_typ;/* No further constraints */
  1698.         break;
  1699.     /* For an attribute, we complete the type checking of the right
  1700.      * argument, and if it must be a static expression, we perform
  1701.      * the appropriate check and extract the attribute.
  1702.      */
  1703.     case as_attribute:
  1704.     case as_range_attribute:
  1705.         type2 = resolve2_attr(expn, context_typ);
  1706.         /* return immediately if resolve_attr failed due to pass1_error */
  1707.         if (type2== (Symbol)0) return;
  1708.         break;
  1709.     /* A conversion may imply a run-time action, or may be used
  1710.      * between types of the same structure to achieve type consistency.
  1711.      * In the later case, do not emit any conversion.
  1712.      * In both cases however, a range check may be needed.
  1713.      */
  1714.  
  1715.     case as_convert:
  1716.         t_node = N_AST1(expn);
  1717.         expn1 = N_AST2(expn);
  1718.         target_type = N_UNQ(t_node);
  1719.         type2 = target_type;
  1720.         types = N_PTYPES(expn1);
  1721.         /* Apply the preference rule to choose a universal meaning for
  1722.          * the expression in case of overloading of operators.
  1723.          */
  1724.         /*tu = set_inter(types, univ_types);*/
  1725.         tu = set_new(0);
  1726.         if (set_mem((char *) symbol_universal_integer, types))
  1727.             tu = set_with(tu, (char *) symbol_universal_integer);
  1728.         if (set_mem((char *) symbol_universal_real, types))
  1729.             tu = set_with(tu, (char *) symbol_universal_real);
  1730.         if (set_size(types) > 1 && set_size(tu) == 1)
  1731.             types = tu;
  1732.         else set_free(tu);
  1733.  
  1734.         /* Verify that original expression is unambiguous. */
  1735.         if (set_size(types) != 1) {
  1736.             errmsg("ambiguous expression for conversion", "4.6", expn1);
  1737.             return;
  1738.         }
  1739.         else {
  1740.             t = (Symbol) set_arb(types);
  1741.             /*    resolve2(expn1, t);  */
  1742.             if (is_numeric(t) && is_numeric(target_type)) {
  1743.                 /* conversions between any two numeric types are allowed. */
  1744.                 /* all done */
  1745.  
  1746.                 resolve2 (expn1, t);
  1747.                 N_AST2 (expn) = expn1;
  1748.                 /*        N_AST1 (expn) = new_name_node (t); */
  1749.                 N_TYPE (expn) = target_type;
  1750.             }
  1751.             /* conversion of records with discriminant will be valid if
  1752.              *   the discriminants have the same values
  1753.              */
  1754.             else if (is_record (target_type) && has_discriminants (target_type)
  1755.               && (root_type (target_type) == root_type (t))) {
  1756.                 resolve2 (expn1, t);
  1757.                 N_KIND (expn) = as_qual_discr;
  1758.                 N_AST1 (expn) = expn1;
  1759.                 N_AST2 (expn) = (Node) 0;
  1760.                 N_TYPE (expn) = target_type;
  1761.             }
  1762.             /* conversion of access values pointing to arrays will be valid
  1763.              * if the indexes of the designated type have the same values
  1764.              */
  1765.  
  1766.             else if (is_access (target_type)
  1767.               && is_array (designated_type(target_type))
  1768.               && (root_type (target_type) == root_type (t))) {
  1769.                 resolve2 (expn1, t);
  1770.                 N_KIND (expn) = as_qual_aindex;
  1771.                 N_AST1 (expn) = expn1;
  1772.                 N_AST2 (expn) = (Node) 0;
  1773.                 N_TYPE (expn) = target_type;
  1774.             }
  1775.             /* conversion of access values pointing to records with discriminant
  1776.              * will be valid if the discriminants of the designated type have
  1777.              * the same values
  1778.              */
  1779.  
  1780.             else if (is_access (target_type)
  1781.               && is_record (designated_type(target_type))
  1782.               && has_discriminants (designated_type(target_type))
  1783.               && (root_type (target_type) == root_type (t))) {
  1784.                 resolve2 (expn1, t);
  1785.                 N_KIND (expn) = as_qual_adiscr;
  1786.                 N_AST1 (expn) = expn1;
  1787.                 N_AST2 (expn) = (Node) 0;
  1788.                 N_TYPE (expn) = target_type;
  1789.             }
  1790.  
  1791.             else if (root_type(target_type) == root_type(t)) {
  1792.                 /* conversions among types derived from a common root. In
  1793.                  * the absence of representation specifications, this is a
  1794.                  * noop, indicated here by having the same type on both sides
  1795.                  */
  1796.                 resolve2 (expn1, t);
  1797.                 N_AST2 (expn) = expn1;
  1798.                 /* N_AST1 (expn) = new_name_node (t); */
  1799.                 N_TYPE (expn) = target_type;
  1800.             }
  1801.             else if (is_array(target_type)) {
  1802.                 /* conversion between array types are allowed, if types of
  1803.                  * indices are convertible and component types are the same.
  1804.                  */
  1805.                 exists = FALSE;
  1806.                 if ( is_array(t)
  1807.                   && no_dimensions(t) == no_dimensions(target_type))
  1808.                     exists = TRUE;
  1809.                 if (exists) {
  1810.                     for (i = 1; i <= no_dimensions(t); i++) {
  1811.                         if (root_type((Symbol)index_types(target_type)[i])
  1812.                            != root_type((Symbol)index_types(t)[i])) {
  1813.                             exists = FALSE; 
  1814.                             break;
  1815.                         }
  1816.                     }
  1817.                 }
  1818.                 if (exists) {
  1819.                     if ( base_type((Symbol)component_type(target_type))
  1820.                       != base_type((Symbol) component_type(t)))
  1821.                         exists = FALSE;
  1822.                 }
  1823.                 if (exists) {          /* convertible */
  1824.                     /* the following lines have been translated from the Setl
  1825.                      * version
  1826.                      */
  1827.  
  1828.                     if (is_access (component_type (t))) {
  1829.                         c1 = designated_type (component_type (t));
  1830.                         c2 = designated_type (component_type (target_type));
  1831.                     }
  1832.                     else {
  1833.                         c1 = component_type (t);
  1834.                         c2 = component_type (target_type);
  1835.                     }
  1836.                     if ((can_constrain (c1)) != (can_constrain (c2))) {
  1837.                         errmsg_l ("component types in array conversion must",
  1838.                           " be both constrained or unconstrained", 
  1839.                           "4.6 (11)", expn);
  1840.                         return;
  1841.                     }
  1842.                     resolve2 (expn1, t);
  1843.                     N_AST2 (expn) = expn1;
  1844.                     N_TYPE (expn) = target_type;
  1845.  
  1846.                     check_array_conversion(expn, t, target_type);
  1847.                 }
  1848.                 else {
  1849.                     errmsg("Invalid array conversion", "4.6", expn);
  1850.                     return;
  1851.                 }
  1852.             }
  1853.             else {
  1854.                 errmsg_id("cannot convert to %", target_type, "4.6", expn);
  1855.             }
  1856.         }
  1857.         /* if (N_KIND(expn) == as_insert) expn = N_AST1(expn);
  1858.          *        N_TYPE(expn) = base_type(type2);
  1859.          *       the result of the conversion must belong to the target subtype.
  1860.          *        if (!is_array(t)) {
  1861.          *            apply_constraint(expn, type2);
  1862.          */
  1863.  
  1864.         apply_constraint (expn, target_type);
  1865.         break;
  1866.     case as_qualify:
  1867.  
  1868.         /* proc resolve2_qualify(expn, context_type);
  1869.          * sem_trace3(3, 'At proc resolve2_qualify ', expn);
  1870.          * [-, to_type, expn1] := expn;
  1871.          * $ No sliding for aggregates here.
  1872.          * may_others := full_others;
  1873.          * full_others := true;
  1874.          * expn2 := eval_static(apply_constraint(resolve2(expn1, to_type),
  1875.          * to_type));
  1876.          * full_others := may_others;                 
  1877.          * return [['qualify', expn2], to_type];
  1878.          */
  1879.         t_node = N_AST1(expn);
  1880.         expn1 = N_AST2(expn);
  1881.         type2 = N_UNQ(t_node);
  1882.  
  1883.         /* This is non-sliding context for aggregates. */
  1884.         may_others = full_others;
  1885.         full_others = TRUE;
  1886.         resolve2(expn1, type2);
  1887.         eval_static(expn1);
  1888.  
  1889.         apply_constraint(expn1, type2);            /* impose checks. */
  1890.  
  1891.         full_others = may_others;
  1892.         break;
  1893.     /* For a subtype, complete the evaluation of the bounds.
  1894.      * If the bounds are literal, the type may be a universal one.
  1895.      * replace it now by the corresponding non-literal type.
  1896.      */
  1897.     case as_subtype:
  1898.         type_node = N_AST1(expn);
  1899.         constraint = N_AST2(expn);
  1900.         low = N_AST1(constraint);
  1901.         high = N_AST2(constraint);
  1902.         /* If the bounds are overloaded, the subtype itself may be an
  1903.          * overloaded expression. Extract the type(s) that are compatible
  1904.          * with context .
  1905.          */
  1906.         ntypes = set_new(0);
  1907.         FORSET(ntype_sym = (Symbol), types, fs1);
  1908.             if (compatible_types(context_typ, ntype_sym))
  1909.                 ntypes = set_with(ntypes, (char *) ntype_sym);
  1910.         ENDFORSET(fs1); 
  1911.         set_free(types);
  1912.         types = ntypes;
  1913.         /* Make sure that only one type is possible. */
  1914.         if (set_size(types) > 1) {
  1915.             /*types = set_diff(types, univ_types);*/
  1916.             ntypes = set_new(0);
  1917.             FORSET(ntype_sym = (Symbol), types, fs1);
  1918.                 if (ntype_sym != symbol_universal_integer
  1919.                   && ntype_sym != symbol_universal_real)
  1920.                     ntypes = set_with(ntypes, (char *) ntype_sym);
  1921.             ENDFORSET(fs1); 
  1922.             set_free(types); 
  1923.             types = ntypes;
  1924.         }
  1925.         if (set_size(types) != 1) {
  1926.             type_error(set_new1((char *)symbol_any), context_typ, 
  1927.               set_size(types), expn);
  1928.             N_TYPE(expn) = symbol_any;
  1929.             return;
  1930.         }
  1931.         else
  1932.             b_type = base_type((Symbol)set_arb(types));
  1933.  
  1934.         /* In the case of a range in a membership op, the type may be a real
  1935.          * one, in which case the precision is inherited from the context .
  1936.          */
  1937.         rtype = root_type(context_typ);
  1938.  
  1939.         if (rtype == symbol_float || rtype == symbol_universal_real)
  1940.             kind = as_digits;
  1941.         else if (is_fixed_type(rtype))
  1942.             kind = as_delta;
  1943.         else
  1944.             kind = as_range;/* $ Discrete type. */
  1945.  
  1946.         if (type_node != OPT_NODE)
  1947.             b_type = N_UNQ(type_node);
  1948.         else {
  1949.             if (kind == as_range) {
  1950.                 if (b_type == symbol_universal_integer) {
  1951.                     b_type = symbol_integer;
  1952.                     if (context_typ == symbol_universal_integer
  1953.                       && (N_KIND(low) == as_op 
  1954.                       || N_KIND(low) == as_un_op 
  1955.                       || N_KIND(high) == as_op
  1956.                       || N_KIND(high) == as_un_op)) {
  1957.                         /* i.e. discrete range in arr def. or iteration rule.*/
  1958.                         /* Not a literal, named number, or attribute(3.6.1(2))*/
  1959.                         errmsg_l("Invalid universal expression in",
  1960.                           " discrete range", "3.6.1", expn);
  1961.                         N_TYPE(expn) = symbol_any;
  1962.                         return;
  1963.                     }
  1964.                 }
  1965.             }
  1966.             else if (kind == as_delta)
  1967.                 b_type = context_typ;
  1968.             else if (kind == as_digits)
  1969.                 b_type = symbol_float;
  1970.         }
  1971.         /* If the type name was not specified, then it is the type
  1972.          * of the bounds.
  1973.          */
  1974.         if (type_node == OPT_NODE) {
  1975.             type_node = node_new(as_simple_name);
  1976.             copy_span(constraint, type_node);
  1977.             N_UNQ(type_node) = b_type;
  1978.             N_AST1(expn) = type_node;
  1979.             N_AST2(expn) = constraint;
  1980.             if (N_AST3_DEFINED(N_KIND(expn))) N_AST3(expn) = (Node)0;
  1981.             if (N_AST4_DEFINED(N_KIND(expn))) N_AST4(expn) = (Node)0;
  1982.         }
  1983.         resolve2(low, b_type);
  1984.         resolve2(high, b_type);
  1985.         /* An index constraint may depend on a discriminant . Verify that
  1986.          * if a discriminant appears, it is by itself, and not as part of
  1987.          * a larger expression. 
  1988.          */
  1989.         check_discriminant(low);
  1990.         check_discriminant(high);
  1991.         eval_static(low);
  1992.         eval_static(high);
  1993.         if (is_discrete_type(b_type)) check_bounds_in_range(low, high, b_type);
  1994.  
  1995.         /* No constraint is imposed on the subtype node itself.*/
  1996.         type2 = b_type;
  1997.         context_typ = b_type;
  1998.         break;
  1999.     case as_call_or_index:
  2000.         /* Find the tree which has a type compatible with the context, and
  2001.          * resolve it.
  2002.           */
  2003.         call_node = N_AST1(expn);
  2004.         index_node = N_AST2(expn);
  2005.         exists = FALSE;
  2006.         FORSET(t = (Symbol), N_PTYPES(call_node), fs1);
  2007.             if (compatible_types(t, context_typ)) {
  2008.                 exists = TRUE;
  2009.                 break;
  2010.             }
  2011.         ENDFORSET(fs1);
  2012.         if (exists) {
  2013.             node = call_node;
  2014.             exists = FALSE;
  2015.             FORSET(t2 = (Symbol), N_PTYPES(index_node), fs1);
  2016.                 if( compatible_types(t2, context_typ)) {
  2017.                     exists = TRUE;
  2018.                     break;
  2019.                 }
  2020.             ENDFORSET(fs1);
  2021.             if (exists) {
  2022.                 remove_conversions(call_node);    /* last chance */
  2023.                 remove_conversions(index_node);
  2024.                 exists = FALSE;
  2025.                 FORSET(t = (Symbol), N_PTYPES(call_node), fs1);
  2026.                     if ( compatible_types(t, context_typ)) {
  2027.                         exists = TRUE;
  2028.                         break;
  2029.                     }
  2030.                 ENDFORSET(fs1);
  2031.                 if (exists) {
  2032.                     node = call_node;
  2033.                     exists = FALSE;
  2034.                     FORSET(t2 = (Symbol), N_PTYPES(index_node), fs1);
  2035.                         if (compatible_types(t2, context_typ)) {
  2036.                             exists = TRUE;
  2037.                             break;
  2038.                         }
  2039.                     ENDFORSET(fs1);
  2040.                     if (exists) {
  2041. #ifdef TBSL
  2042.                         type_error(set_new1('call or index'), context_typ, 2,
  2043.                           expn);
  2044. #endif
  2045.                     }
  2046.                 }
  2047.                 else node = index_node;
  2048.             }
  2049.         }
  2050.         else node = index_node;
  2051.         resolve2(node, context_typ);
  2052.         copy_attributes(node, expn);
  2053.         type2 = N_TYPE(node);
  2054.         break;
  2055.     default:
  2056.         /* Other operators require no propagation */
  2057.         type2 = (Symbol) set_arb(types);
  2058.         break;
  2059.     }
  2060.  
  2061.     if (compatible_types(context_typ, type2)) N_TYPE(expn) = type2;
  2062.     else {
  2063.         errmsg_type("Incorrect type for expression. Expect %", context_typ,
  2064.           "none", expn);
  2065.     }
  2066. }
  2067.  
  2068. static Symbol resolve2_attr(Node expn, Symbol context_typ)    /*;resolve2_attr*/
  2069. {
  2070.     Forset    fs1;
  2071.     Set        types;
  2072.     int        attrkind, dim, out_c;
  2073.     Symbol    type2;
  2074.     Const    con;
  2075.     Node    attr_node, arg1, arg2;
  2076.     Set        types1, types2;
  2077.     Symbol    type1, t2, itype1;
  2078.  
  2079.     types = N_PTYPES(expn);
  2080.     attr_node = N_AST1(expn);
  2081.     arg1 = N_AST2(expn);
  2082.     arg2 = N_AST3(expn);
  2083.     /*  The type of the right argument is determined by the attribute,
  2084.      *  and has already been evaluated in the case of array attributes.
  2085.      */
  2086.     /*attribute = N_VAL(attr_node); -- should be dead  ds 3-13-86*/
  2087.     attrkind = (int) attribute_kind(expn);
  2088.     types1 = N_PTYPES(arg1);
  2089.     types2 = N_PTYPES(arg2);
  2090.     type1 = (Symbol) set_arb(types1);
  2091.  
  2092.     if (attrkind == ATTR_PRED 
  2093.       ||attrkind == ATTR_SUCC 
  2094.       ||attrkind == ATTR_POS 
  2095.       ||attrkind == ATTR_IMAGE)
  2096.         t2 = base_type(type1);
  2097.     else if (attrkind == ATTR_VALUE)
  2098.         t2 = symbol_string;
  2099.     else if (attrkind == ATTR_VAL) {
  2100.         Symbol t;
  2101.         Set otypes2;
  2102.         otypes2 = types2;
  2103.         types2 = set_new(0);
  2104.         FORSET(t = (Symbol), otypes2, fs1);
  2105.             if (compatible_types(t, symbol_integer_type))
  2106.                 types2 = set_with(types2, (char *) t);
  2107.         ENDFORSET(fs1);
  2108.         if (set_size(types2) == 0) {
  2109.             errmsg("Second argument of VAL must be of some integer type",
  2110.              "Annex A", arg2);
  2111.             return (Symbol)0;
  2112.         }
  2113.         else if (set_size(types2) == 1)
  2114.             t2 = (Symbol) set_arb(types2);
  2115.         else if (set_mem((char *) symbol_universal_integer, types2))
  2116.             t2 = symbol_universal_integer;
  2117.         else {
  2118.             errmsg("ambiguous argument for attribute VAL", "Annex A", arg2);
  2119.             return (Symbol)0;
  2120.         }
  2121.     }
  2122.     else
  2123.         t2 = symbol_integer;
  2124.  
  2125.     if  (attrkind != ATTR_O_FIRST && attrkind != ATTR_T_FIRST
  2126.       && attrkind != ATTR_O_LAST && attrkind != ATTR_T_LAST
  2127.       && attrkind != ATTR_O_RANGE && attrkind != ATTR_T_RANGE
  2128.       && attrkind != ATTR_O_LENGTH && attrkind != ATTR_T_LENGTH)
  2129.         resolve2(arg2, t2);
  2130.     if (t2 == symbol_universal_integer)        /* possible for VAL */
  2131.         specialize(arg2, symbol_integer);
  2132.     if ((attrkind == ATTR_POSITION || attrkind == ATTR_FIRST_BIT
  2133.       || attrkind == ATTR_LAST_BIT) && N_KIND(arg1) != as_selector) {
  2134.         errmsg("attribute must apply to selected component", "13.7.2", arg1);
  2135.     }
  2136.     /*
  2137.      * If the left argument is a type, or if it is a constrained
  2138.      * object, then evaluate the attribute on the type, statically if
  2139.      * possible.
  2140.      */
  2141.     /*
  2142.      * All attributes, except those that  are functions,  can be applied
  2143.      * to  an out parameter, because  they do not require reading of the
  2144.      * object, or read  only its bounds. On the other hand,      if the pre-
  2145.      * fix is an access type, it cannot be an an out parameter (4.1(4)).
  2146.      */
  2147.     out_c = out_context; /* Save current setting*/
  2148.     out_context = !reads_prefix(attrkind, type1);
  2149.     itype1 = type1;
  2150.  
  2151.     if (is_array(type1)
  2152.       && (attrkind == ATTR_O_FIRST || attrkind == ATTR_T_FIRST
  2153.       || attrkind == ATTR_O_LAST || attrkind == ATTR_T_LAST
  2154.       || attrkind == ATTR_O_RANGE || attrkind == ATTR_T_RANGE
  2155.       || attrkind == ATTR_O_LENGTH || attrkind == ATTR_T_LENGTH)) {
  2156.         /*    The second argument indicates the dimension whose attribute
  2157.          * is sought. It must be a static integer(this has been checked
  2158.          * already).
  2159.          */
  2160.         if (!is_static_expr(arg2))
  2161.             dim = 1;    /* By default. */
  2162.         else {
  2163.             con = (Const) N_VAL(arg2);
  2164.             dim = con->const_value.const_int;
  2165.         }
  2166.         itype1 = (Symbol) (index_types(type1)[dim]);
  2167.     }
  2168.  
  2169.     if (is_type_node(arg1)) {
  2170.         /* This might cause problems in eval_static. */
  2171.         /* In at least some cases, N_PTYPES has been set (cf. 4a.c line 1009),
  2172.          * so here we clear N_PTYPES lest it be mistaken for N_TYPE (DS 9-18-86)
  2173.          */
  2174.         N_PTYPES(arg1) = (Set) 0;
  2175.         N_UNQ(arg1) = itype1;
  2176.     }
  2177.     else if (attrkind == ATTR_COUNT) {
  2178.         /* entry name is fully resolved in first pass. */
  2179.         ;        /* no op */
  2180.     }
  2181.     else {
  2182.         resolve2(arg1, type1);
  2183.     }
  2184.     out_context = out_c; /* restore    */
  2185.  
  2186.     if (in_univ_attributes(attrkind)) {
  2187.         if (is_static_expr(expn)) {
  2188.             /* Specialize value if context is not universal.*/
  2189.             eval_static(expn);
  2190.             specialize(expn, context_typ);
  2191.         }
  2192.         /* in nay case indicate desired context type for subsequent conversion*/
  2193.         type2 = base_type(context_typ);
  2194.     }
  2195.     else {                 /*$$$ TBSL: check for FIRST_BIT, LAST_BIT*/
  2196.         type2 = (Symbol) set_arb(types);
  2197.     }
  2198.     return type2;
  2199. }
  2200.  
  2201. static int in_univ_attributes(int attrkind)                /*;in_univ_attributes*/
  2202. {
  2203.     /* test if type of attribute is universal type */
  2204.     static int attrs[] = {
  2205.         ATTR_AFT, ATTR_COUNT, ATTR_DIGITS, ATTR_EMAX, ATTR_FIRST_BIT, ATTR_FORE,
  2206.         ATTR_LAST_BIT, ATTR_O_LENGTH, ATTR_T_LENGTH, ATTR_MACHINE_EMAX,
  2207.         ATTR_MACHINE_EMIN, ATTR_MACHINE_MANTISSA, ATTR_MACHINE_RADIX,
  2208.         ATTR_MANTISSA, ATTR_POS, ATTR_POSITION, ATTR_SAFE_EMAX, ATTR_O_SIZE,
  2209.         ATTR_T_SIZE, ATTR_STORAGE_SIZE, ATTR_WIDTH, ATTR_DELTA, ATTR_EPSILON,
  2210.         ATTR_LARGE, ATTR_SMALL, ATTR_SAFE_LARGE, ATTR_SAFE_SMALL,
  2211.         ATTR_O_CONSTRAINED, ATTR_T_CONSTRAINED, ATTR_MACHINE_OVERFLOWS,
  2212.         ATTR_MACHINE_ROUNDS, ATTR_CALLABLE, ATTR_TERMINATED, 999    };
  2213.     int i;
  2214.     for (i = 0; ; i++) {
  2215.         if (attrs[i] == 999) return FALSE;
  2216.         if (attrs[i] == attrkind) return TRUE;
  2217.     }
  2218. }
  2219.  
  2220. static void check_bounds_in_range(Node low, Node high, Symbol b_type)
  2221.                                                     /*;check_bounds_in_range*/
  2222. {
  2223.     /* check if the bounds of an array with a subtype_declaration are
  2224.      * in the bounds of the base_type, when static. (When not static,
  2225.      * a qual_range is introduced on as_convert).
  2226.      */
  2227.  
  2228.     Node    lbd_range, ubd_range;
  2229.     int     low_val, high_val, lbd_val, ubd_val;
  2230.     Tuple   b_range_tup;
  2231.     Const      low_const, high_const, lbd_const, ubd_const;
  2232.  
  2233.     /* Previous error such as missing declaration for variable*/
  2234.     if (b_type == symbol_any) return;
  2235.     b_range_tup   = SIGNATURE(b_type);
  2236.     lbd_range     = (Node) b_range_tup[2];
  2237.     ubd_range     = (Node) b_range_tup[3];
  2238.     if (N_KIND(low) == as_qualify) low = N_AST2(low);
  2239.     if (N_KIND(high) == as_qualify) high = N_AST2(high);
  2240.  
  2241.     if (is_static_expr(low) && is_static_expr(high)
  2242.       && is_static_expr(lbd_range) && is_static_expr(ubd_range))  {
  2243.         low_const = (Const) N_VAL(low);
  2244.         high_const = (Const) N_VAL(high);
  2245.         lbd_const = (Const) N_VAL(lbd_range);
  2246.         ubd_const = (Const) N_VAL(ubd_range);
  2247.         const_check(low_const, CONST_INT);
  2248.         const_check(high_const, CONST_INT);
  2249.         const_check(lbd_const, CONST_INT);
  2250.         const_check(ubd_const, CONST_INT);
  2251.         low_val = INTV(low_const);
  2252.         high_val = INTV(high_const);
  2253.         lbd_val = INTV(lbd_const);
  2254.         ubd_val = INTV(ubd_const);
  2255.  
  2256.         if ((lbd_val > ubd_val && low_val <= high_val)
  2257.           || ((low_val <= high_val) && (low_val < lbd_val || low_val > ubd_val
  2258.           || high_val > ubd_val || high_val < lbd_val))) {
  2259.             create_raise(low, symbol_constraint_error);
  2260.             return;
  2261.         }
  2262.     }
  2263. }
  2264.  
  2265. static void check_array_conversion(Node expn, Symbol from_t, Symbol to_t)
  2266.                                                 /*;check_array_conversion */
  2267. {
  2268.     /* verify that in an array conversion, source and target component types
  2269.      * have the same constraints.
  2270.      */
  2271.  
  2272.     Symbol from_c, to_c;
  2273.     Tuple  checks;
  2274.     Tuple from_i, to_i;
  2275.     int i;
  2276.  
  2277.     checks = tup_new(0);
  2278.  
  2279.     from_c = component_type(from_t);
  2280.     to_c = component_type(to_t);
  2281.  
  2282.     while (is_access (from_c)) {
  2283.         from_c = designated_type (from_c);
  2284.         to_c = designated_type (to_c); 
  2285.     }
  2286.  
  2287.     if (from_c == to_c) {
  2288.         ;
  2289.     }
  2290.     else if (is_scalar_type(from_c))
  2291.         checks = tup_with(checks, (char *) new_check_bounds_node(from_c, to_c));
  2292.     else if (is_record (from_c) && has_discriminants (from_c))
  2293.         checks = new_check_disc_node (from_c, to_c); 
  2294.     else if (is_array(from_c)) {
  2295.         /* index subtypes must be equal */
  2296.         from_i = index_types(from_c);
  2297.         to_i = index_types(to_c);
  2298.         for (i = 1; i<= tup_size(from_i); i++) {
  2299.             checks = tup_with(checks,
  2300.               (char *) new_check_bounds_node( (Symbol)from_i[i],
  2301.               (Symbol)to_i[i]));
  2302.         }
  2303.     }
  2304.     /* TBSL: check values of discriminants for record types. */
  2305.  
  2306.     if (tup_size(checks) > 0) {
  2307.         make_insert_node(expn, checks, copy_node(expn));
  2308.         /* This line has to be deleted in order to reuse the function
  2309.       in case of conversion of array access values 
  2310.       N_TYPE(expn) = to_t; */
  2311.     }
  2312. }
  2313.  
  2314. static int reads_prefix(int attrkind, Symbol type1)
  2315.                                                             /*;reads_prefix*/
  2316. {
  2317.     /* Used to determine whether an attribute can apply to an out parameter.
  2318.      * see tests A62006d, B62006c, B85007C.
  2319.      */
  2320.  
  2321.     if  (attrkind == ATTR_BASE
  2322.       || attrkind == ATTR_POS
  2323.       || attrkind == ATTR_PRED
  2324.       || attrkind == ATTR_SUCC
  2325.       || attrkind == ATTR_VAL
  2326.       || attrkind == ATTR_VALUE)
  2327.         return TRUE;
  2328.  
  2329.     if (is_access(type1))  return TRUE;
  2330.     return FALSE;
  2331. }
  2332.